home *** CD-ROM | disk | FTP | other *** search
- Path: isonews.bbn.hp.com!hpbblb!news
- From: Matthias Dittrich <matti>
- Newsgroups: comp.lang.c
- Subject: Re: help with strcmp
- Date: 4 Apr 1996 12:41:08 GMT
- Organization: Hewlett-Packard Co.
- Message-ID: <4k0g14$as0@hpbblb.bbn.hp.com>
- References: <4jpiek$lp6@blaze.cs.jhu.edu>
- NNTP-Posting-Host: trabant.bbn.hp.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
- X-URL: news:4jpiek$lp6@blaze.cs.jhu.edu
-
- lasher@hops.cs.jhu.edu (John E. Davis) wrote:
- >For some reason when I try to compare the strings in the following
- >snippet I consistently get a core dump (running on a UNIX machine running
- >Solaris). Could anyone point out what may be going wrong? I have run it
- >through the debugger and that was no help at all for me. here is the
- >code snippet:
- >
- >#include <stdio.h>
- >#include <stdlib.h>
- >#include <string.h>
- >
- >void setup(FILE *);
- >
- >void main(int argc, char *argv[])
- >{
- >char buf[20], data[40], *buff, *arg, *fp;
- >FILE *handle, *dest;
- >int n;
- >
- >handle = fopen(argv[1], "r");
- >if(dest = fopen( "dbuild.out", "w")) setup(dest);
- >
- >while(!feof(handle)) {
- > n = 0;
- > fp = fgets(data, 40, handle);
- > if ( strcasecmp(fp, "<action>\n") == 0) /* the coredump is here */
- > parseAction(handle, dest);
- > else if ( strcasecmp(fp, "<control>\n") == 0)
- > parseControl(handle, dest);
- > else if ( strcasecmp(fp, "<general>\n") == 0)
- > parseGeneral(handle, dest);
- > printf("%s", data);
- > }
- >fclose(dest);
- >
- >}
- >
- fgets returns a NULL-pointer if EOF is reached. I think this causes the
- core dump.
- Check the return value before using the pointer.
-
- Good luck,
- Matthias
-
-